package Client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.Set;

import Interfaces.Task;

public class Client {

	public static void main (String args[]) throws InterruptedException{
		Runnable r = new Runnable() {
			public void run() {
				Set<String> set=new HashSet<String>();
				set.add("spong");
				Task newTask=new Task(3,set);
				Socket socket=null;
		        try {
					socket = new Socket("127.0.1.1", 10099);
					System.out.println("created socket");
					ObjectOutputStream out=new ObjectOutputStream(socket.getOutputStream());
					out.writeObject(newTask);
					System.out.println("Object sent to server");
					System.out.println("reading response");
					BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
					System.out.println(in.readLine());
					socket.close();
				} catch (UnknownHostException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} 				
			}
		} ;
		new Thread(r).start();
		Thread.sleep(500);
		Runnable r2 = new Runnable() {
			public void run() {
				Set<String> set=new HashSet<String>();
				set.add("spong");
				Task newTask=new Task(4,set);
				Socket socket=null;
		        try {
					socket = new Socket("127.0.1.1", 10099);
					System.out.println("created socket");
					ObjectOutputStream out=new ObjectOutputStream(socket.getOutputStream());
					out.writeObject(newTask);
					System.out.println("Object sent to server");
					System.out.println("reading response");
					BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
					System.out.println(in.readLine());
					socket.close();
				} catch (UnknownHostException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} 				
			}
		} ;
		new Thread(r2).start();
		Thread.sleep(500);
		Runnable r3 = new Runnable() {
			public void run() {
				Set<String> set=new HashSet<String>();
				set.add("spong");
				Task newTask=new Task(5,set);
				Socket socket=null;
		        try {
					socket = new Socket("127.0.1.1", 10099);
					System.out.println("created socket");
					ObjectOutputStream out=new ObjectOutputStream(socket.getOutputStream());
					out.writeObject(newTask);
					System.out.println("Object sent to server");
					System.out.println("reading response");
					BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
					System.out.println(in.readLine());
					socket.close();
				} catch (UnknownHostException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} 				
			}
		} ;
		new Thread(r3).start();
	}
}
